package com.clickpaas.materialsprocurement.dao.Impl;

import com.bizcloud.ipaas.t0ba0ba6afb694026b6b4e4e048af2b43.d20210202135416.codegen.PurchaseorderApi;
import com.bizcloud.ipaas.t0ba0ba6afb694026b6b4e4e048af2b43.d20210202135416.model.*;
import com.clickpaas.materialsprocurement.bean.MateralsDTOBean;
import com.clickpaas.materialsprocurement.dao.PurchaseOrderDao;
import com.clickpaas.materialsprocurement.entity.PurchaseOrderEntity;
import com.clickpaas.materialsprocurement.utils.SpringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Repository
public class PurchaseOrderDaoImpl implements PurchaseOrderDao {

    @Resource
    private MateralsDTOBean materalsDtoBean;
    @Resource
    private PurchaseorderApi purchaseorderApi;

    private List<PurchaseOrderDTOResponse> queryPurchaseOrderInfo(PurchaseOrderDTO purchaseOrderDTO){
        DataResponseListPurchaseOrderDTO purchaseOrderUsingPOST = purchaseorderApi.findPurchaseOrderUsingPOST(purchaseOrderDTO);
        if(null == purchaseOrderUsingPOST
                || null == purchaseOrderUsingPOST.getData()
                || purchaseOrderUsingPOST.getData().size()<=0
                || !"SUCCESS".equals(purchaseOrderUsingPOST.getMessage())){
            log.info("当前查询的数据：【{}】",purchaseOrderUsingPOST);
            return null;
        }
        return purchaseOrderUsingPOST.getData();
    }

    /**
     * 根据条件查询采购订单对象数据
     *
     * @param purchaseOrderEntity
     */
    @Override
    public List<PurchaseOrderDTOResponse> getPurchaseOrderByCondtion(PurchaseOrderEntity purchaseOrderEntity) {
        PurchaseOrderDTO purchaseOrderDTO = materalsDtoBean.purchaseOrderDTO();
        try {
            SpringUtil.copyPropertiesIgnoreNull(purchaseOrderEntity,purchaseOrderDTO);
        }catch (Exception e){
            log.info("对象转换失败！转换的对象是：【{}】",purchaseOrderEntity);
        }
        return queryPurchaseOrderInfo(purchaseOrderDTO);
    }
}
